<template>
  <div class="job-detail-container">
    <!-- 头部信息 -->
    <div class="job-header">
      <h1 class="job-title">
        <span>{{ jobDetail.title }}</span
        ><span class="salary">{{ jobDetail.salary }}</span>
      </h1>
      <div class="job-meta">
        <span>{{ jobDetail.workAddress }}</span>
        <span>|</span>
        <span>{{ jobDetail.workRange }}</span>
        <span>|</span>
        <span>{{ jobDetail.education }}</span>
      </div>

      <div class="job-tags">
        <span class="tag" v-for="ele in jobDetail.welfare" :key="ele">{{
          ele
        }}</span>
      </div>

      <!-- 公司信息 -->
      <div class="company-info">
        <div class="info">
          <div
            class="compony-img"
            v-for="ele in jobDetail.companyInfo"
            :key="ele"
          >
            <img :src="ele.logoUrl" alt="" />
          </div>
          <div class="info-right">
            <h3
              class="company-name"
              v-for="ele in jobDetail.companyInfo"
              :key="ele"
            >
              {{ ele.title }}
            </h3>
            <div class="company-tags">
              <span v-for="ele in jobDetail.companyInfo" :key="ele">{{
                ele.companyNumber
              }}</span>
            </div>
          </div>
        </div>
        <div class="next">
          <button class="btn">立即投递</button>
        </div>
      </div>
    </div>

    <!-- 分隔线 -->
    <div class="divider"></div>

    <!-- 职位详情 -->
    <div class="job-section">
      <h2 class="section-title">职位详情</h2>
      <div class="section-content">
        <p class="section-item">岗位职责：</p>
        <ol class="responsibilities">
          <li v-for="ele in jobDetail.description" :key="ele">
            {{ ele.title }}
          </li>
        </ol>
      </div>
    </div>

    <!-- 分隔线 -->
    <div class="divider"></div>

    <!-- 任职资格 -->
    <div class="job-section">
      <h2 class="section-title">任职资格</h2>
      <div class="section-content">
        <ol class="qualifications">
          <li v-for="ele in jobDetail.works" :key="ele">{{ ele.title }}</li>
        </ol>
      </div>
    </div>

    <!-- 底部操作栏 -->
    <div class="action-bar">
      <button class="apply-btn">立即聊天</button>
    </div>
  </div>
</template>

<script setup>
import { getJobsDetail } from "../../api/home";
import { ref, watch } from "vue";
import { useRoute } from "vue-router";

const route = useRoute();
const id = ref(route.query.id);
const jobDetail = ref({});
const getDetail = async () => {
  let res = await getJobsDetail({ workid: id.value });
  console.log("详情数据：", res);
  jobDetail.value = res.data; // 假设是这样
};
// 响应式监听 id 变化并请求数据
watch(
  () => route.query.id,
  async (newId) => {
    if (newId) {
      id.value = newId;
      await getDetail();
    }
  },
  { immediate: true }
);
</script>

<style scoped>
.job-detail-container {
  padding: 16px;
  padding-bottom: 80px;
  background-color: #fff;
  min-height: 100vh;
  box-sizing: border-box;
  font-family: "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  color: #333;
}

/* 头部信息 */
.job-header {
  margin-bottom: 16px;
  box-shadow: 0 0.06rem 0.21rem #01409938;
  border-radius: 8px;
  padding: 16px;
}

.job-title {
  font-size: 22px;
  font-weight: bold;
  margin: 0 0 8px 0;
  color: #333;
}

.salary {
  float: right;
  color: #149639;
}

.job-meta {
  font-size: 14px;
  color: #666;
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
}

.job-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tag {
  font-size: 12px;
  padding: 4px 8px;
  background-color: #f5f5f5;
  border-radius: 4px;
  color: #666;
}

/* 分隔线 */
.divider {
  height: 1px;
  background-color: #f0f0f0;
  margin: 16px 0;
}

/* 公司信息 */
.company-info {
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.company-info .compony-img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
}
.company-info .compony-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.info {
  display: flex;
  align-items: center;
}
.next .btn {
  padding: 5px;
  color: #149639;
  border: 1px solid #149639;
  border-radius: 6px;
  background-color: #fff;
}
.company-name {
  font-size: 16px;
  font-weight: bold;
  margin: 0 0 8px 0;
  color: #333;
}

.company-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  color: #666;
}

/* 职位详情部分 */
.job-section {
  margin-bottom: 20px;
}

.section-title {
  font-size: 18px;
  font-weight: bold;
  margin: 0 0 12px 0;
  color: #333;
}

.section-content {
  font-size: 15px;
  line-height: 1.6;
  color: #333;
}

.section-item {
  font-weight: bold;
  margin: 0 0 8px 0;
}

.responsibilities,
.qualifications {
  margin: 0;
  padding-left: 20px;
}

.responsibilities li,
.qualifications li {
  margin-bottom: 8px;
}

/* 底部操作栏 */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  background-color: #fff;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  text-align: center;
  z-index: 999;
}

.apply-btn {
  width: 100%;
  height: 44px;
  font-size: 16px;
  font-weight: bold;
  background-color: #149639;
  color: white;
  border: none;
  border-radius: 22px;
}
</style>
